package com.zb.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Assert;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.constant.WorkConstant;
import com.zb.entity.AccounLoginInfo;
import com.zb.entity.ZjAccount;
import com.zb.entity.ZjWorkOrder;
import com.zb.entity.ZjWorkReminder;
import com.zb.mapper.ZjWorkReminderMapper;
import com.zb.result.PageUtil;
import com.zb.service.*;
import com.zb.view.ViewNetworkEmpAccount;
import com.zb.view.ViewNetworkEmpDetail;
import com.zb.vo.OrderReminderVo;
import com.zb.vo.WorkLogVo;
import com.zb.vo.WorkReminderListVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 工单催单表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2023-10-10
 */
@Service
public class ZjWorkReminderServiceImpl extends ServiceImpl<ZjWorkReminderMapper, ZjWorkReminder> implements ZjWorkReminderService {
    @Resource
    private ZjWorkOrderService workOrderService;
    @Resource
    private ZjAccountService accountService;
    @Resource
    private ViewNetworkEmpDetailService viewNetworkEmpDetailService;
    @Resource
    private ViewNetworkEmpAccountService viewNetworkEmpAccountService;


    // 根据工单ID获取工单催单列表
    @Override
    public Map<String, Object> getReminderList(Long workId, PageUtil pageUtil) {
        PageUtil.setPageLimit(pageUtil);
        QueryWrapper<ZjWorkReminder> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.select("id", "emp_type", "emp", "content", "gmt_create");
        wrapper.eq("work_id", workId);
        Page<ZjWorkReminder> page = this.page(new Page<>(pageUtil.getPage(), pageUtil.getLimit()), wrapper);
        List<WorkReminderListVo> voList = page.getRecords().stream().map(rem -> {
            WorkReminderListVo vo = new WorkReminderListVo();
            BeanUtil.copyProperties(rem, vo);
            vo.setCreateTime(rem.getGmtCreate());
            vo.setEmpType(Objects.equals(1, rem.getEmpType())? "系统客服" : Objects.equals(2, rem.getEmpType())? "工单客户" :
                    Objects.equals(3, rem.getEmpType())? "移动端网点" : Objects.equals(4, rem.getEmpType())?"第三方系统接口" : "品牌商家");
            return vo;
        }).toList();
        return PageUtil.pageList(page.getCurrent(), page.getSize(), page.getTotal(), voList);
    }
}
